# Create your views here.

from django.http import HttpResponse
from cStringIO import StringIO
from PIL import Image, ImageDraw, ImageFont

def captcha_image(request, captcha):
    text = request.session.get(captcha, 'xxx')

    image = Image.new('RGB', (85, 30), (39, 36, 81))
    font = ImageFont.truetype('/home/nachopro/desarrollo/nachopro/captcha/font.ttf', 30)
    draw = ImageDraw.Draw(image)
    draw.text((2, 2), text, font = font, fill = (153, 204, 0))
    out = StringIO()
    image.save(out,"JPEG")
    out.seek(0)
    response = HttpResponse(mimetype='image/jpeg')
    response.write(out.read())
    return response
